<%@page import="cn.kgcnews.pojo.User"%>
<%@page import="cn.kgcnews.service.impl.UserServiceImpl"%>
<%@page import="cn.kgcnews.service.UserService"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
      //接收用户的请求数据
      request.setCharacterEncoding("UTF-8");
      String userName=request.getParameter("userName"); 
      String userPwd=request.getParameter("userPass");
      String userType=request.getParameter("userType");
      //将数据封装为User对象
      User user=new User(userName, userPwd, Integer.valueOf(userType), null);
      //添加业务逻辑层的引用
      UserService userService=new UserServiceImpl();
      int result=userService.registerUser(user);
      if(result==1){
           //添加成功
           out.println("<script>alert('恭喜您，添加成功');location.href='userlist.jsp';</script>");
      }else if(result==0){
           //用户名被占用
           out.println("<script>alert('添加失败，用户名被占用');history.back();</script>");
      }else{
           //注册失败
           out.println("<script>alert('添加失败');history.back();</script>");
      }
    %>

